import request from '@/utils/request';
import * as URL from '@/constants/api';
import * as tool from "@/utils/tools";
import dayjs from 'dayjs';
// 获取员工列表
export function getStaffList(params) {
  return request({
    url: URL.STAFF_LIST,
    method: 'GET',
    params,
  }).then(res => {
    res.data.data.rows = res.data.data.rows.map(d => ({
      ...d,
      timeOfEntry: dayjs(d.timeOfEntry).format('YYYY-MM-DD'),
      correctionTime: dayjs(d.correctionTime).format('YYYY-MM-DD'),
    }));
    return res.data.data;
  });
}
// 新增员工
export function addStaff(data) {
  return request({
    url: URL.STAFF_LIST,
    method: 'POST',
    data,
  }).then(res => res.data)
}
// 根据id获取员工角色信息
export function staffRoleInfo(id) {
  return request({
    url: `${URL.STAFF_LIST}/${id}`,
    method: 'GET',
  }).then(res => res.data.data.roleIds)
}
// 给员工分配角色
export function assignRoles(data) {
  return request({
    url: URL.ASSIGNP_ROLES,
    method: 'PUT',
    data,
  }).then(res => res.data)
}
// 根据id删除员工
export function delStaff(id) {
  return request({
    url: `${URL.STAFF_LIST}/${id}`,
    method: 'DELETE',
  }).then(res => res.data)
}
// 查询企业的部门列表
export function getDepartmentList() {
  return request({
    url: URL.DEPARTMENT_LIST,
    method: 'GET',
  }).then(res => res.data.data)
}
